import re # 正则表达式,进行文字匹配
from applications.common.utils.sqlUtil import SqlUtil

# re.finditer(r"\d+", "12a32bc43jf3")

# m = re.match(r'^(\d{3})-(\d{3,8})$', '010-12345')
# print(m.groups())

# phone = "2004-959-559 # 这是一个电话号码"

# # 删除注释
# num = re.sub(r'#.*$', "", phone)
# print("电话号码 : ", num)

# # 移除非数字的内容
# num = re.sub(r'\D', "", phone)
# print("电话号码 : ", num)
# firstDeleteRe = re.compile(r'###((.|\n)*?)###')
baseSql = '''
    select t.id , group2.name , t.sort,t.second_id,t.mian_id,group2.type
    from ye_many_relationship t
    left join (
    select t.* from ye_group t where t.type = '2'
    ) group2 on group2.id = t.second_id
    ###<%=where,and%>
        and t.mian_id = :mian_id
        ***<%=keyword%> and group2.name like '%'|| :keyword ||'%' ***
        ***<%=key%> and group2.name like '%'|| :key ||'%' ***
    ###
    order by t.sort asc
'''
baseSql2 = '''
    select t.id , group2.name , t.sort,t.second_id,t.mian_id,group2.type
    from ye_many_relationship t
    left join (
    select t.* from ye_group t where t.type = '2'
    ) group2 on group2.id = t.second_id
    where
        t.mian_id = :mian_id
        ***<%=keyword%> and group2.name like '%'|| :keyword ||'%' ***
        ***<%=key%> and group2.name like '%'|| :key ||'%' ***
    order by t.sort asc
'''
baseSql3 = '''
    select t.id , group2.name , t.sort,t.second_id,t.mian_id,group2.type
    from ye_many_relationship t
    left join (
    select t.* from ye_group t where t.type = '2'
    ) group2 on group2.id = t.second_id
    ###<%=where,and%>
        and t.mian_id = :mian_id
        ***<%=keyword%> and group2.name like '%'|| :keyword ||'%' ***
        ***<%=key%> and group2.name like '%'|| :key ||'%' ***
    ###
    ###<%=where,and%>
        ***<%=keyword1%> 
            and group4.name like '%'|| :keyword1 ||'%'  
            11111
        
        ***
        ***<%=key1%> and group4.name like '%'|| :key1 ||'%' ***
    ###
    order by t.sort asc
'''

# print(re.sub(firstDeleteRe,"",baseSql))
# print('=======================================================================================')
# testobj = 1
# print(testobj is not None)
# SqlUtil().dynamicHandleSql(baseSql,dict(keyword="keyword"))
# finallySql = SqlUtil().dynamicHandleSql(baseSql = baseSql,params = dict(keyword="keyword"))
# finallySql = SqlUtil().dynamicHandleSql(baseSql = baseSql2,params = dict(keyword="keyword"))
finallySql = SqlUtil().dynamicHandleSql(baseSql = baseSql3,params = dict(keyword="keyword",keyword1="keyword1"))

print(finallySql)






# print(SqlUtil().validStrNone(
# validStr = '''

   
# '''))
# print(SqlUtil().validStrNone(
# validStr = '''
   

# '''))
# print(SqlUtil().validStrNone(
# validStr = '''
#    asdfasd   adfasdf
# fasdfadsf
# '''))